{% include '/templates/admin_header.html' %}
<!-- Content - Existing Assets -->
<div id="content" class="flex">
  <h1>zerodyproject-d Assets</h1>
  <div id="server-status">
    <div class="module" id="changelist">
      <form id="list-form" action="" method="post" name="delete_assets">
        <div class="results">
          <table id="result_list">
            <thead>
              <tr>
                <th scope="col" class="action-checkbox-column">
                  <div class="text">
                    <span><input type="checkbox" id="action-toggle" /></span>
                  </div>
                  <div class="clear"></div>
                </th>
                <th scope="col" class="sortable">
                  <div class="text">
                    <a href="?o=1.-1">ID</a>
                  </div>
                  <div class="clear"></div>
                </th>
                <th scope="col" class="sortable"><div class="text">Name</div></th>
                <th scope="col" class="sortable"><div class="text">Platform</div></th>
                <th scope="col" class="sortable"><div class="text">Version</div></th>
                <th scope="col" class="sortable"><div class="text">URL</div></th>
                <th scope="col" class="sortable"><div class="text">updated at</div></th>
              </tr>
            </thead>
            <tbody>
              {% for asset in assets %}
              <tr class="row{{ asset.index % 2 }}">
                <td class="action-checkbox"><input type="checkbox" class="action-select" value="{{asset.id}}" name="selected" /></td>
                <td>{{asset.id}}</td>
                <td>{{asset.name}}</td>
                <td>{{asset.platform}}</td>
                <td>{{asset.version}}</td>
                <td>{{asset.url}}</td>
                <td>{{asset.created_at}}</td>
              </tr>
              {% endfor %}
            </tbody>
          </table>
        </div>
        <div class="submit-row">
          <input type="submit" value="Delete" class="default" name="_delete" />
        </div>
      </form>
    </div>
  </div>
</div>
<!-- End Content - Existing Assets -->

<!-- Content - Add Asset -->
<script type="text/javascript">
	function validateForm() {
		if (document.adding_form.name.value == ""
				|| document.adding_form.version.value == "") {
			alert("Required fields must be filled out!");
			return false;
		}
		for (x = 0; x < document.adding_form.platforms.length; x++) {
			if (document.adding_form.platforms[x].selected) {
				return true;
			}
		}

		alert("Required fields must be filled out!");
		return false;
	}
</script>
<script src="https://code.jquery.com/jquery-1.9.1.js">
</script>
<script type="text/javascript">
  jQuery(function($) {
    $(this).on("change", '#id_data',
      function() {
    	var filename = $('#id_data').val().split('\\').pop().split('/').pop().split('.')[0];
        $('#id_name').val(filename);
      }
    );
  });
</script>
<form enctype="multipart/form-data" onsubmit="return(validateForm());" action="{{upload_url}}" method="post" name="adding_form">
  <div id="content" class="flex">
    <h1>Add asset</h1>
    <div id="new-asset">
      <fieldset class="module aligned ">
        <div class="form-row field-platform">
          <div>
            <label for="id_platform" class="required">Platform:</label> <select name="platforms" multiple size="2">
              <option value="1">IOS</option>
              <option value="2">PlayStore</option>
            </select>
          </div>
        </div>
        <div class="form-row field-version">
          <div>
            <label for="id_version" class="required">Version:</label> <input id="id_version" type="number" class="vIntegerField" value="1" name="version" maxlength="9999" />
          </div>
        </div>
        <div class="form-row field-data">
          <div>
            <label for="id_data" class="required">Data:</label> <input id="id_data" type='file' name='file' />
          </div>
        </div>
        <div class="form-row field-name">
          <div>
            <label for="id_name" class="required">Name:</label> <input id="id_name" type="text" class="vTextField" name="name" maxlength="32" />
          </div>
        </div>
        <div class="submit-row">
          <p class="backward-box">
            <a href="/admin/">Back</a>
          </p>
          <input type="submit" value="Save" class="default" name="_save" />
        </div>
      </fieldset>
    </div>
  </div>
</form>
<!-- End Content - Add Asset -->
{% include '/templates/admin_footer.html' %}
